/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Pedidos.Producto.Vista;

import Pedidos.Producto.Controlador.ProductoControlador;
import javax.swing.JTable;
import sape.MenuControlador;

/**
 *
 * @author Diego
 */
public class Producto extends javax.swing.JInternalFrame {

    /**
     * Creates new form Producto
     */
   
    public ProductoControlador controlador=null;


    public Producto(MenuControlador menuControlador) {
        
        this.controlador=new ProductoControlador(this,menuControlador);
        initComponents();
    }

    Producto() {
      
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlPrincipal = new javax.swing.JPanel();
        pnlInformacionProducto = new javax.swing.JPanel();
        lbNombre = new javax.swing.JLabel();
        tbNombre = new javax.swing.JTextField();
        lbPrecio = new javax.swing.JLabel();
        btnAgregar = new javax.swing.JButton();
        btnBuscar = new javax.swing.JButton();
        tbPrecio = new javax.swing.JTextField();
        lbNuevosSoles = new javax.swing.JLabel();
        pnlResultadoBusqueda = new javax.swing.JPanel();
        scrScrollResultado = new javax.swing.JScrollPane();
        tblTablaResultado = new javax.swing.JTable();

        setBorder(null);
        setForeground(new java.awt.Color(0, 0, 51));
        setTitle("Producto");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setEnabled(false);
        setMaximumSize(new java.awt.Dimension(786, 730));
        setPreferredSize(new java.awt.Dimension(786, 730));
        setRequestFocusEnabled(false);

        pnlInformacionProducto.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detalle", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 1, 13), new java.awt.Color(0, 51, 102))); // NOI18N
        pnlInformacionProducto.setForeground(new java.awt.Color(0, 51, 153));
        pnlInformacionProducto.setFont(new java.awt.Font("Segoe UI", 1, 13)); // NOI18N

        lbNombre.setFont(new java.awt.Font("Segoe UI", 0, 13)); // NOI18N
        lbNombre.setForeground(new java.awt.Color(0, 51, 102));
        lbNombre.setText("Nombre");

        tbNombre.setFont(new java.awt.Font("Segoe UI", 0, 13)); // NOI18N
        tbNombre.setForeground(new java.awt.Color(0, 51, 102));

        lbPrecio.setFont(new java.awt.Font("Segoe UI", 0, 13)); // NOI18N
        lbPrecio.setForeground(new java.awt.Color(0, 51, 102));
        lbPrecio.setText("Precio");

        btnAgregar.setFont(new java.awt.Font("Segoe UI", 1, 13)); // NOI18N
        btnAgregar.setForeground(new java.awt.Color(0, 51, 102));
        btnAgregar.setText("Agregar");
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });

        btnBuscar.setFont(new java.awt.Font("Segoe UI", 1, 13)); // NOI18N
        btnBuscar.setForeground(new java.awt.Color(0, 51, 102));
        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        tbPrecio.setFont(new java.awt.Font("Segoe UI", 0, 13)); // NOI18N
        tbPrecio.setForeground(new java.awt.Color(0, 51, 102));

        lbNuevosSoles.setFont(new java.awt.Font("Segoe UI", 0, 13)); // NOI18N
        lbNuevosSoles.setForeground(new java.awt.Color(0, 51, 102));
        lbNuevosSoles.setText("Nuevos Soles");

        javax.swing.GroupLayout pnlInformacionProductoLayout = new javax.swing.GroupLayout(pnlInformacionProducto);
        pnlInformacionProducto.setLayout(pnlInformacionProductoLayout);
        pnlInformacionProductoLayout.setHorizontalGroup(
            pnlInformacionProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInformacionProductoLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(pnlInformacionProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbNombre)
                    .addComponent(lbPrecio))
                .addGap(52, 52, 52)
                .addGroup(pnlInformacionProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlInformacionProductoLayout.createSequentialGroup()
                        .addComponent(tbPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbNuevosSoles))
                    .addComponent(tbNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlInformacionProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnAgregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnBuscar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(23, 23, 23))
        );
        pnlInformacionProductoLayout.setVerticalGroup(
            pnlInformacionProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInformacionProductoLayout.createSequentialGroup()
                .addGroup(pnlInformacionProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlInformacionProductoLayout.createSequentialGroup()
                        .addComponent(btnAgregar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBuscar))
                    .addGroup(pnlInformacionProductoLayout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(pnlInformacionProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbNombre)
                            .addComponent(tbNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlInformacionProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbPrecio)
                            .addComponent(tbPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbNuevosSoles))))
                .addContainerGap(42, Short.MAX_VALUE))
        );

        pnlResultadoBusqueda.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Resultado", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 1, 13), new java.awt.Color(0, 51, 102))); // NOI18N
        pnlResultadoBusqueda.setFont(new java.awt.Font("Segoe UI", 1, 13)); // NOI18N

        tblTablaResultado.setAutoCreateRowSorter(true);
        tblTablaResultado.setFont(new java.awt.Font("Ubuntu", 0, 12)); // NOI18N
        tblTablaResultado.setModel(controlador);
        tblTablaResultado.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tblTablaResultado.setDropMode(javax.swing.DropMode.ON_OR_INSERT_ROWS);
        tblTablaResultado.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblTablaResultadoMouseClicked(evt);
            }
        });
        scrScrollResultado.setViewportView(tblTablaResultado);

        javax.swing.GroupLayout pnlResultadoBusquedaLayout = new javax.swing.GroupLayout(pnlResultadoBusqueda);
        pnlResultadoBusqueda.setLayout(pnlResultadoBusquedaLayout);
        pnlResultadoBusquedaLayout.setHorizontalGroup(
            pnlResultadoBusquedaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlResultadoBusquedaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(scrScrollResultado, javax.swing.GroupLayout.PREFERRED_SIZE, 699, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlResultadoBusquedaLayout.setVerticalGroup(
            pnlResultadoBusquedaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlResultadoBusquedaLayout.createSequentialGroup()
                .addComponent(scrScrollResultado, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 28, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout pnlPrincipalLayout = new javax.swing.GroupLayout(pnlPrincipal);
        pnlPrincipal.setLayout(pnlPrincipalLayout);
        pnlPrincipalLayout.setHorizontalGroup(
            pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(pnlResultadoBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 723, Short.MAX_VALUE)
                    .addComponent(pnlInformacionProducto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlPrincipalLayout.setVerticalGroup(
            pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPrincipalLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(pnlInformacionProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(pnlResultadoBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pnlPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 1, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        this.controlador.agregar();
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void tblTablaResultadoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblTablaResultadoMouseClicked
        if(evt.getClickCount()==2){
         JTable target = (JTable)evt.getSource();
         int row = target.getSelectedRow();
         int column = target.getSelectedColumn();
         this.controlador.detalle(row,column);   
        }
    }//GEN-LAST:event_tblTablaResultadoMouseClicked

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        
        this.controlador.buscar(this.tbNombre,this.tbPrecio);
    }//GEN-LAST:event_btnBuscarActionPerformed

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JLabel lbNombre;
    private javax.swing.JLabel lbNuevosSoles;
    private javax.swing.JLabel lbPrecio;
    private javax.swing.JPanel pnlInformacionProducto;
    private javax.swing.JPanel pnlPrincipal;
    private javax.swing.JPanel pnlResultadoBusqueda;
    private javax.swing.JScrollPane scrScrollResultado;
    private javax.swing.JTextField tbNombre;
    private javax.swing.JTextField tbPrecio;
    public javax.swing.JTable tblTablaResultado;
    // End of variables declaration//GEN-END:variables
}
